<script>
    //189000503  左香菊
    //1.字面量方式创建对象
    console.log("1.字面量方式创建对象");
    var obj1 = {
        name: "刘备",
        sex: "男",
        run: function() {
            console.log("跑");
        }
    }

    //2.Object方式创建对象
    console.log("2.Object方式创建对象");
    var obj2 = new Object();
    obj2.name = "刘备";
    obj2.sex = "男";
    obj2.run = function() {
        console.log("跑");
    }

    //3.用工厂模式创建对象
    console.log("3.用工厂模式创建对象");
    function createPerson(p_name, p_sex, p_run) {
        var tempPerson = new Object();
        tempPerson.name = p_name;
        tempPerson.sex = p_sex;
        tempPerson.run = p_run;
        return tempPerson;
    }
    var obj3 = createPerson("刘备", "男", new Function("consle.log('跑')"));

    //4.用构造函数创建对象
    console.log("4.用构造函数创建对象");
    function Student(name, sex) {
        this.name = name;
        this.sex = sex;
        this.run = function() {
            console.log(this.name + "跑");
        }
    }
    var obj4 = new Object("刘备", "男");

    //5.用原型模式创建对象
    console.log("5.用原型模式创建对象");
    function Person() {
        }
        Person.prototype.name = "刘备";
        Person.prototype.sex = "男";
        Person.prototype.run = function() {
            console.log(this.name + "跑");
        };
    var obj5 = new Person();
    console.log(obj5);
    obj5.run();

    //6.this指向  window
    console.log("6.this指向");
    function fun() {
        console.log(this);
    }
    fun();

    //7.Dog继承Animal
    console.log("7.Dog继承Animal");
    function Animal(name){
        this.name = name;
    }
    function Dog(name,color){
        Animal.call(this.name);
        this.color = color;
    }
    var obj7 = new Dog("小吕","黑色");

    //8.
    console.log("8.继承");
    function Person(name){
        this.name = name;
    }
    Person.prototype.run = function(){
        console.log("跑");
    }
    function Worker(name, salary) {
        Person.call(this,name);
        this.salary = salary;
    }
    Worker.prototype = new Person();
    var obj8 = new Worker("赵云", 100);
    console.log(obj8);

    //9.用原型实现继承
    console.log("9.用原型实现继承");
    var person1 = {
        name: "刘备",
        sex: "男" ,
        run: function(){
            console.log("跑");
        }
    }
    var person2 = Object.create(person1);
    console.log(person2);

    //10
    console.log("10.继承");
    function inheritPrototype(sFun, pFun){
        var myPrototype = new Object(pFun.prototype);
        myPrototype.constructor = sFun;
        sFun.prototype = myPrototype;
    }
    function Person(name){
        this.name = name;
    }
    Person.prototype.run = function(){
        console.log("跑");
    }
    function Worker(name, salary){
        Person.call(this,name);
        this.salary = salary;
    }
    inheritPrototype(Worker,Person);
    var worker1 = new Worker("赵云", 100);
    console.log(worker1);
</script>